$(() => {
    const $container = $('body > .container');
    //刷新
    $container.on('refresh', (_, data) => {
        refreshDataGrid(data);
    });
    // 导出
    $container.on('export', (_, data) => {
        const { examGrid } = data;
        if (examGrid) {
            var workbook = new ExcelJS.Workbook();
            var worksheet = workbook.addWorksheet('sheet');

            DevExpress.excelExporter.exportDataGrid({
                component: examGrid.instance(),
                worksheet: worksheet
            }).then(function () {
                workbook.xlsx.writeBuffer().then(function (buffer) {
                    saveAs(new Blob([buffer], { type: 'application/octet-stream' }), '数据统计.xlsx');
                });
            });
        }
    });
    // 刷新表格
    const refreshDataGrid = (data) => {
        //获取表格
        const { params } = data;
        if (params) {
            const { reloadGrid } = params;
            if (reloadGrid instanceof Function) {
                reloadGrid();
            }
        } else {
            const { examGrid } = data;
            examGrid.refresh();
        }
    }
});
